Paging, Subsort Recordset
am 02.08.2005 07:15:56 von KevinThis is a multi-part message in MIME format.
------=_NextPart_000_0079_01C596E6.96A3AA40
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Can anyone point me to a code example where a recordset.absolutepage is =
sorted independantly of the original recordset. That is; if I populate =
an ADO recordset with an ORDER BY ListingDate clause, and I need to =
(subsort) recordset.absolutepage five of my paging on another field, say =
for example AskingPrice, I'm stuck.
My goal is for my users to be able to page through my recordset, sort a =
page if desired, and continue through the recordset. The records on any =
page are sorted, and the same records are displayed, just in a new =
(subsort) oder.=20
I'm not using the data controls, just plain ASP...
Thanks
Kev
Current code below...
<%
check_security(2)
%>
<%
If Session("UserID") =3D "" Then
Response.Redirect "Login.asp"
End if
=20
Dim rsItems, strSort
=20
strSort =3D request("sortby")
=20
strSQL =3D "SELECT Item.ItemID, Users.CompanyName, =
EquipmentTypes.EquipName, Item.EquipmentType, Item.LoadSize, =
Item.PickupDate, Item.SPCountry, Item.SPState, " & _
"Item.SPCity, Item.DPCountry, Item.DPState, Item.DPCity, =
Item.Description, Item.AskingPrice, Item.SellerID, Item.ListingDate, =
Item.ExpirationDate, Item.ItemStatus " & _
"FROM (Item INNER JOIN EquipmentTypes ON Item.EquipmentType =
=3D EquipmentTypes.EquipCode) LEFT JOIN Users ON Item.SellerID =3D =
Users.UserID " & _
"WHERE Item.ExpirationDate > #" & FormatDateTime(Now,2) & "# =
" & _
"AND ItemStatus =3D 'Active' "
If request("LoadSize") <> "" then
strSQL =3D strSQL & "AND LoadSize =3D '" & request("LoadSize") & "' =
"
End if
=20
If request("EquipmentType") <> "" then
strSQL =3D strSQL & "AND EquipmentType =3D '" & =
request("EquipmentType") & "' "
End if
=20
If request("SPCountry") <> "" then
strSQL =3D strSQL & "AND SPCountry =3D '" & request("SPCountry") & =
"' "
End if
If request("SPState") <> "" then
strSQL =3D strSQL & "AND SPState =3D '" & request("SPState") & "' "
End if
If request("DPCountry") <> "" then
strSQL =3D strSQL & "AND DPCountry =3D '" & request("DPCountry") & =
"' "
End if
If request("DPState") <> "" then
strSQL =3D strSQL & "AND DPState =3D '" & request("DPState") & "' "
End if
strSQL =3D strSQL & "ORDER BY PickupDate;"
page_no =3D request("page_no")
if page_no =3D "" then page_no =3D 1
Set rsItems =3D Server.CreateObject("ADODB.Recordset")
=20
if strSql <> "" then
rsItems.CursorLocation =3D 3
rsItems.CacheSize =3D 5
rsItems.Sort =3D "PickupDate, " & strSort
rsItems.Open strSql, objConn
if not rsItems.EOF then=20
rsItems.MoveFirst
rsItems.PageSize =3D 5
max_count =3D cInt(rsItems.PageCount)
num_recs =3D rsItems.RecordCount
rsItems.AbsolutePage =3D page_no
results =3D true
for each tmp in request.querystring
if tmp <> "page_no" AND tmp <> "sortby" then
request_string =3D request_string & tmp & "=3D" & =
request.querystring(tmp) & "&"
end if
next
else
results =3D false
rsItems.Close
end if
else
results =3D false
end if
rec_count =3D 0
%>
Browse Loads |
the column name. type description. |
<%
if results =3D true then
%>
<% else %>
No loads currently listed
<%=20
end if=20
if max_count > 1 then=20
%>
page_no > 1 then %>
=3Drequest.servervariables("script_name") %>?<% =3Drequest_string =
%>page_no=3D1&sortby=3D<% =3Drequest("sortby")%>">First
<% else %>
<% end if %>
page_no > 1 then %>
=3Drequest.servervariables("script_name") %>?<% =3Drequest_string =
%>page_no=3D<% =3Dpage_no-1 =
%>&sortby=3D<%=3Drequest("sortby")%>">Previous
<% else %>
<% end if %>
Records: <%=3Dnum_recs%>
cInt(page_no) < cInt(max_count) then %>
=3Drequest.servervariables("script_name") %>?<% =3Drequest_string =
%>page_no=3D<% =3Dpage_no+1 %>&sortby=3D<% =
=3Drequest("sortby")%>">Next
<% end if %>
cInt(page_no) < cInt(max_count) then %>
=3Drequest.servervariables("script_name") %>?<% =3Drequest_string =
%>page_no=3D<% =3DcInt(max_count) %>&sortby=3D<% =
=3Drequest("sortby")%>">Last
<% end if %>
<% end if %>
------=_NextPart_000_0079_01C596E6.96A3AA40
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
charset=3Dwindows-1252">
where a=20
recordset.absolutepage is sorted independantly of the =
original=20
recordset. That is; if I populate an ADO recordset with an ORDER =
BY=20
ListingDate clause, and I need to (subsort)=20
recordset.absolutepage five of my paging on another =
field, say=20
for example AskingPrice, I'm stuck.
page through=20
my recordset, sort a page if desired, and continue through the=20
recordset. The records on any page are sorted, and the same =
records are=20
displayed, just in a new (subsort) oder.
plain=20
ASP...
file=3D"Utilities.asp"-->
<link href=3D"styles/main.css" =
rel=3D"stylesheet"=20
type=3D"text/css">
<!--#include=20
file=3D"header.asp"-->
<!--#include=20
file=3D"Menu.asp"-->
<%
=20
check_security(2)
%>
<%
Then
Response.Redirect "Login.asp"
End=20
if
Dim rsItems, strSort
strSort =
=
request("sortby")
strSQL =3D "SELECT Item.ItemID,=20
Users.CompanyName, EquipmentTypes.EquipName, Item.EquipmentType, =
Item.LoadSize,=20
Item.PickupDate, Item.SPCountry, Item.SPState, " &=20
_
=
"Item.SPCity,=20
Item.DPCountry, Item.DPState, Item.DPCity, Item.Description, =
Item.AskingPrice,=20
Item.SellerID, Item.ListingDate, Item.ExpirationDate, Item.ItemStatus " =
&=20
_
"FROM =
(Item=20
INNER JOIN EquipmentTypes ON Item.EquipmentType =3D =
EquipmentTypes.EquipCode) LEFT=20
JOIN Users ON Item.SellerID =3D Users.UserID " &=20
_
"WHERE =
Item.ExpirationDate > #" & FormatDateTime(Now,2) & "# " & =
_
"AND=20
ItemStatus =3D 'Active' "
request("LoadSize") <>=20
"" then
strSQL =3D strSQL & "AND =
LoadSize =3D '"=20
& request("LoadSize") & "' "
End=20
if
If request("EquipmentType") <> =
""=20
then
strSQL =3D strSQL & "AND =
EquipmentType =3D '"=20
& request("EquipmentType") & "' "
End=20
if
If request("SPCountry") =
<>=20
"" then
strSQL =3D strSQL & "AND =
SPCountry =3D '"=20
& request("SPCountry") & "' "
End =
if
<> ""=20
then
strSQL =3D strSQL & "AND SPState =
=3D '" &=20
request("SPState") & "' "
End if
request("DPCountry") <>=20
"" then
strSQL =3D strSQL & "AND =
DPCountry =3D '"=20
& request("DPCountry") & "' "
End =
if
<> ""=20
then
strSQL =3D strSQL & "AND DPState =
=3D '" &=20
request("DPState") & "' "
End if
strSQL &=20
"ORDER BY PickupDate;"
request("page_no")
if=20
page_no =3D "" then page_no =3D 1
Server.CreateObject("ADODB.Recordset")
if =
strSql=20
<> "" then
rsItems.CursorLocation =3D =
3
rsItems.CacheSize=20
=3D 5
rsItems.Sort =3D "PickupDate, " & =
strSort
rsItems.Open=20
strSql, objConn
if not rsItems.EOF then=20
rsItems.MoveFirst
rsItems.Page=
Size =
5
max_count =
cInt(rsItems.PageCount)
num_recs =
rsItems.RecordCount
rsItems.AbsolutePage =
page_no
results =3D true
for =
each tmp in=20
request.querystring
if tmp <> "page_no" =
AND tmp=20
<> "sortby" then
request_string =
request_string & tmp & "=3D" & request.querystring(tmp) =
&=20
"&"
end=20
if
next
else
results =
false
rsItems.Close
end =
if
else
results =
false
end if
rec_count =
0
%>
<table=20
cellpadding=3D"0"=20
cellspacing=3D"0">
=
=20
<tr>
 =
; =20
<td> </td>
&n=
bsp; =20
</tr>
=20
<tr>
 =
; =20
<td><h1>Browse=20
Loads</h1></td>
=
=20
</tr>
=20
<tr>
 =
; =20
<td><li>Click Company Name to bid on the=20
load.</li>
 =
; =20
<li>Click the column headers to sort each Pickup Date by the =
column=20
name.</li>
 =
; =20
<li>Place your mouse over the Type code to see the full type=20
description.</li>
&nbs=
p; =20
<li>You cannot bid on your own=20
loads.</li></td>
 =
; =20
</tr>
=20
<tr>
 =
; =20
<td> </td>
&n=
bsp; =20
</tr>
=20
</table>
<%
=20
<table width=3D"760px" cellpadding=3D'0'=20
cellspacing=3D'0'>
=
=20
<tr>
 =
; =20
<td=20
class=3D'tdHeader'>Company</td>
 =
; =20
<td class=3D'tdHeader'><a=20
href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
=3Drequest_string=20
%>page_no=3D<% =3Dpage_no=20
%>&sortby=3DLoadSize">Size</a></td>
=
=20
<td class=3D'tdHeader'><a=20
href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
=3Drequest_string=20
%>page_no=3D<% =3Dpage_no=20
%>&sortby=3DEquipmentType">Type</a></td>
&=
nbsp; =20
<td class=3D'tdHeader'><a=20
href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
=3Drequest_string=20
%>page_no=3D<% =3Dpage_no %>&sortby=3DPickupDate">Pickup =
Date</a></td>
&n=
bsp; =20
<td class=3D'tdHeader'><a=20
href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
=3Drequest_string=20
%>page_no=3D<% =3Dpage_no %>&sortby=3DSPCity">Starting=20
Point</a></td>
&=
nbsp; =20
<td class=3D'tdHeader'><a=20
href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
=3Drequest_string=20
%>page_no=3D<% =3Dpage_no=20
%>&sortby=3DDPCity">Destination</a></td>
&=
nbsp; =20
<td class=3D'tdHeader'><a=20
href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
=3Drequest_string=20
%>page_no=3D<% =3Dpage_no =
%>&sortby=3DAskingPrice">Payment=20
Amt</a></td>
&nb=
sp; =20
</tr>
=20
<%
<=20
rsItems.Pagesize)
=
<tr>
 =
; =20
<% If Session("UserID") <> "" AND Session("UserID") <>=20
rsItems("SellerID") Then=20
%>
&nbs=
p;=20
<td align=3D"left" class=3D'tdData'><a=20
href=3D'Bid.asp?Item=3D<%=3DrsItems("ItemID")%>'><%=3DrsItems=
("ItemReference")%></a></td>
&n=
bsp; =20
<% Else=20
%>
&nbs=
p;=20
<td class=3D'tdData'=20
align=3D'left'><%=3DrsItems("ItemReference")%></td>
&nb=
sp; =20
<% End If=20
%>
&nbs=
p;=20
<td class=3D'tdData' align=3D'center'><%=3D rsItems("LoadSize") =
%></td>
 =
; =20
<td class=3D'tdData' align=3D'center'><a=20
title=3D'<%=3DrsItems("EquipName")%>'><%=3DrsItems("Equipment=
Type")%></a></td>
&=
nbsp; =20
<td align=3D'center' class=3D'tdData'><%=
rsItems("PickupDate")%></td>
&n=
bsp; =20
<td align=3D'left' nowrap class=3D'tdData'> <a =
href=3D" href=3D'http://www.mapquest.com/maps/map.adp?country=3D<%=3DrsItems("SPCo=
untry")%>&state=3D<%=3DrsItems("SPState")%>&city=3D<%=3DrsItems("=
SPCity")%>&CID=3Dlfmaplink'>http://www.mapquest.com/maps /map.adp?coun=
try=3D<%=3DrsItems("SPCountry")%>&state=3D<%=3DrsItems("SPSt=
ate")%>&city=3D<%=3DrsItems("SPCity")%>&CID=3Dlfmaplink<=
/A>"=20
target=3D"_blank"><font color=3D"#FF0000"=20
size=3D"1">Map</font></a> <%=3D =
rsItems("SPCity") &=20
", " &=20
rsItems("SPState")%></td>
 =
; =20
<td align=3D'left' nowrap class=3D'tdData'> <a =
href=3D" href=3D'http://www.mapquest.com/maps/map.adp?country=3D<%=3DrsItems("DPCo=
untry")%>&state=3D<%=3DrsItems("DPState")%>&city=3D<%=3DrsItems("=
DPCity")%>&CID=3Dlfmaplink'>http://www.mapquest.com/maps /map.adp?coun=
try=3D<%=3DrsItems("DPCountry")%>&state=3D<%=3DrsItems("DPSt=
ate")%>&city=3D<%=3DrsItems("DPCity")%>&CID=3Dlfmaplink<=
/A>"=20
target=3D"_blank"><font color=3D"#FF0000"=20
size=3D"1">Map</font></a> <%=3D =
rsItems("DPCity") &=20
", " & rsItems("DPState")=20
%></td>
 =
; =20
<td class=3D'tdData' align=3D'right'><%=
formatcurrency(rsItems("AskingPrice"))=20
%> </td>
&=
nbsp; =20
</tr>
=20
<%
rsItems.MoveNext
rec_count =3D rec_count +=20
1
loop
rsItems.Close
Set rsItems =
Nothing
%>
=20
</table>
<% else=20
%>
=20
<center>
=
<h2>No loads currently=20
listed</h2>
=20
</center>
<%=20
=20
<table width=3D"760px" cellpadding=3D"0" cellspacing=3D"0"=20
class=3D"NavTable">
 =
; =20
<tr>
 =
; =20
<td align=3Dcenter width=3D"20%" class=3DNavFont><% if page_no =
> 1 then=20
%>
&nbs=
p; =20
<a class=3DHeaderFont href=3D"<% =
=3Drequest.servervariables("script_name")=20
%>?<% =3Drequest_string %>page_no=3D1&sortby=3D<%=20
=3Drequest("sortby")%>">First</a>
=
=20
<% else=20
%>
&nbs=
p; =20
<% end if=20
%>
&nbs=
p;=20
</td>
&nbs=
p; =20
<td align=3Dcenter width=3D"20%" class=3DNavFont><% if page_no =
> 1 then=20
%>
&nbs=
p; =20
<a class=3DHeaderFont href=3D"<% =
=3Drequest.servervariables("script_name")=20
%>?<% =3Drequest_string %>page_no=3D<% =3Dpage_no-1=20
%>&sortby=3D<%=3Drequest("sortby")%>">Previous</a><=
BR> &nbs=
p; =20
<% else=20
%>
&nbs=
p; =20
<% end if=20
%>
&nbs=
p;=20
</td>
&nbs=
p; =20
<td align=3Dcenter width=3D"20%" class=3DNavFont>=20
Records: <%=3Dnum_recs%>=20
</td>
&nbs=
p; =20
<td align=3Dcenter width=3D"20%" class=3DNavFont><% if =
cInt(page_no) <=20
cInt(max_count) then=20
%>
&nbs=
p; =20
<a class=3DHeaderFont href=3D"<% =
=3Drequest.servervariables("script_name")=20
%>?<% =3Drequest_string %>page_no=3D<% =3Dpage_no+1 =
%>&sortby=3D<%=20
=3Drequest("sortby")%>">Next</a>
&=
nbsp; =20
<% end if=20
%>
&nbs=
p;=20
</td>
&nbs=
p; =20
<td align=3Dcenter width=3D"20%" class=3DNavFont><% if =
cInt(page_no) <=20
cInt(max_count) then=20
%>
&nbs=
p; =20
<a class=3DHeaderFont href=3D"<% =
=3Drequest.servervariables("script_name")=20
%>?<% =3Drequest_string %>page_no=3D<% =3DcInt(max_count)=20
%>&sortby=3D<%=20
=3Drequest("sortby")%>">Last</a>
&=
nbsp; =20
<% end if=20
%>
&nbs=
p;=20
</td>
=20
</tr>
=20
</table>
<% end if %>
<!--#include=20
file=3D"footer.asp"-->
------=_NextPart_000_0079_01C596E6.96A3AA40--